<?php $db = new Mypdo(); ?><?php


if (!empty($_SESSION['login'])&&!empty($_SESSION['email'])){

$locaManager = new LocataireManager($db);
$loca = $locaManager->getList();

?>
<h1>Liste des locataires</h1>
<table class="tableau" >
    <tr>
        <th>Nom</th>
        <th>Prenom</th>
        <th>Location</th>
        <th>Détail</th>
        <th>Loyers</th>
    </tr>
    <?php foreach ($loca as $valeur) {
        $loc = $locaManager->getLocation($valeur->getIdLoca());
        $pers = $locaManager->getPersonne($valeur->getIdLoca());

//var_dump($pers);
        ?>

        <tr>
            <td><?php
                if(gettype($pers) == 'object'){
                    echo $pers->getNomPers();
                }else{
                    foreach($pers as $val){
                        echo $val->getNomPers().'<br/>';
                    }
                }

        ?></td>
            <td><?php
                if(gettype($pers) == 'object'){
                    echo $pers->getPrenomPers();
                }else{
                    foreach($pers as $val){
                        echo $val->getPrenomPers().'<br/>';
                    }
                }?></td>
            <td><?php
                if(gettype($loc) == 'object'){
                    echo $loc->getNomLoc();
                }else{
                    foreach($loc as $val){
                        echo $val->getNomLoc().'<br/>';
                    }
                }
          ?></td>
                <td><input id="detail" name="detail" type="button" onclick="document.location.href='index.php?page=114&id=<?php echo $valeur->getIdLoca(); ?>'" /></td>
            <td><input id="loyer" name="loyer" type="button" onclick="document.location.href='index.php?page=212&id=<?php echo $valeur->getIdLoca(); ?>'" /></td>

        </tr>

        <?php
        } ?>
</table>

    <input id="add" name="add" type="button" onclick="document.location.href='index.php?page=104'" value="Ajouter Locataire" />


<?php }else{
    header('Location: index.php');
}